package com.subaiqiao.yunshiyuan.basis.pojo;

import static com.subaiqiao.yunshiyuan.basis.constant.SystemConst.Network.ERROR;
import static com.subaiqiao.yunshiyuan.basis.constant.SystemConst.Network.SUCCESS;

/**
 * @author CaoZhaoYu
 * @version_createTime 2022/12/1 12:13
 * @jdk_version 1.8
 * @product_name IntelliJ IDEA
 */
public class ResultData<T> {

    private Integer status;
    private T data;
    private Integer recordNumber;
    private String errorCode;
    private T errorMsg;

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getRecordNumber() {
        return recordNumber;
    }

    public void setRecordNumber(Integer recordNumber) {
        this.recordNumber = recordNumber;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public T getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(T errorMsg) {
        this.errorMsg = errorMsg;
    }

    public ResultData() {}

    public ResultData(Integer status, T data, Integer recordNumber, String errorCode, T errorMsg) {
        this.status = status;
        this.data = data;
        this.recordNumber = recordNumber;
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public static <T> ResultData<T> success(T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setStatus(SUCCESS);
        resultData.setData(data);
        return resultData;
    }

    public static <T> ResultData<T> error(T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setStatus(ERROR);
        resultData.setErrorMsg(data);
        return resultData;
    }

    public static <T> ResultData<T> error(T data, String errorCode) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setStatus(ERROR);
        resultData.setErrorMsg(data);
        resultData.setErrorCode(errorCode);
        return resultData;
    }


}
